  <?php
  // RCI code start
  echo $cre_RCI->get('global', 'top');
  echo $cre_RCI->get('indexnested', 'top');
  // RCI code eof
  ?>
  <!-- Bof content.index_nested.tpl.php-->
   <table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
 
<?php
   if ( (ALLOW_CATEGORY_DESCRIPTIONS == 'true') && (tep_not_null($category['categories_heading_title'])) ) {
	 $title1 = $category['categories_heading_title'];
   } else {
	 $title1 = HEADING_TITLE;
   }
?>

<?php 
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(false, false, $title1);
}
?>
 
      <tr>
        <td>
        	<table border="0" width="100%" cellspacing="0" cellpadding="0">



<?php if ($category['categories_image']!='') { ?>
         
				<tr>
            		<td class="pageHeading" align="right">
             			<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
                			<tr>
                    			<td width="11" class="bgr_4"><img src="<?php echo DIR_WS_TEMPLATES . TEMPLATE_NAME?>/images/spacer.gif" alt="" width="11" height="1" /><br></td>
                    			<td>
									<img src="<?php echo DIR_WS_TEMPLATES . TEMPLATE_NAME?>/images/spacer.gif" alt="" width="1" height="1" /><br>
									<?php echo tep_image(DIR_WS_IMAGES . $category['categories_image'], $category['categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?>

                    			</td>
                    			<td width="11" class="bgr_5"><img src="<?php echo DIR_WS_TEMPLATES . TEMPLATE_NAME?>/images/spacer.gif" alt="" width="11" height="1" /><br></td>
                			</tr>
              			</table>            
            		</td>
          		</tr>
                
<?php } ?>

<?php if ( (ALLOW_CATEGORY_DESCRIPTIONS == 'true') && (tep_not_null($category['categories_description'])) ) { ?>
   				 <tr>
            		<td align="left" colspan="2" class="category_desc"><?php echo $category['categories_description']; ?></td>
    			</tr>
<?php } ?>
        	</table>
		</td>
	</tr>
	<tr>
		<td>
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
            	<tr>
                	<td>
                    	<table border="0" width="100%" cellspacing="0" cellpadding="0">
                        	<tr>
<?php
    if (isset($cPath) && strpos('_', $cPath)) {
// check to see if there are deeper categories within the current category
      $category_links = array_reverse($cPath_array);
      for($i=0, $n=sizeof($category_links); $i<$n; $i++) {
        $categories_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "'");
        $categories = tep_db_fetch_array($categories_query);
        if ($categories['total'] < 1) {
          // do nothing, go through the loop
        } else {
          $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
          break; // we've found the deepest category the customer is in
        }
      }
    } else {
      $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$current_category_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
    }

    $number_of_categories = tep_db_num_rows($categories_query);

    $rows = 0;
    while ($categories = tep_db_fetch_array($categories_query)) {
      $rows++;
      $cPath_new = tep_get_path($categories['categories_id']);
      $width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';
      echo '<td align="center" class="smallText" width="' . $width . '" valign="top" style="padding:5px;">';
	  
	  
	  	echo tm_image_border('<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . tep_image(DIR_WS_IMAGES . $categories['categories_image'], $categories['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '</a>');
		
		
	    echo '<br style="line-height:5px;"><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . $categories['categories_name'] . '</a>';
	  
	  '</td>' . "\n";
      if ((($rows / MAX_DISPLAY_CATEGORIES_PER_ROW) == floor($rows / MAX_DISPLAY_CATEGORIES_PER_ROW)) && ($rows != $number_of_categories)) {
        echo '              </tr>' . "\n";
        echo '              <tr>' . "\n";
      }
    }

// needed for the new products module shown below
    $new_products_category_id = $current_category_id;
?>
							</tr>
						</table>
					</td>
				</tr>
       		</table>
		</td>
	</tr>
    
<?php 
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_bottom();
}
?>
    <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
    </tr>
    <tr>
        <td>
            <?php include(DIR_WS_TEMPLATES .TEMPLATE_NAME . '/mainpage_modules/' . FILENAME_NEW_PRODUCTS); ?>
        </td>
    </tr>
</table>
<?php
// RCI code start
echo $cre_RCI->get('indexnested', 'bottom');
echo $cre_RCI->get('global', 'bottom');
// RCI code eof
 ?><!-- Eof content.index_nested.tpl.php-->